package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketRole;
import com.cskaoyan.market.db.domain.MarketRoleExample;
import com.cskaoyan.market.db.mapper.MarketRoleMapper;
import com.cskaoyan.market.service.MarketRoleService;
import com.cskaoyan.market.util.MyBatisUtil;
import com.cskaoyan.market.vo.RoleVo;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName MarketAdminServiceImpl
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2023/5/5 11:08
 * @Version V1.0
 **/
@Service
public class MarketRoleServiceImpl implements MarketRoleService {

//    绝对不能将 SqlSession 实例的引用放在一个类的静态域，甚至一个类的实例变量也不行。 也绝不能将 SqlSession 实例的引用放在任何类型的托管作用域中，比如 Servlet 框架中的 HttpSession。
    //SqlSession sqlSession;
    @Autowired
    MarketRoleMapper marketRoleMapper;
    @Override
    public List<RoleVo> options() {
        List<MarketRole> marketRoles = marketRoleMapper.selectByExample(new MarketRoleExample());
        ArrayList<RoleVo> roleVos = new ArrayList<>();
        for (MarketRole marketRole : marketRoles) {
            RoleVo roleVo = new RoleVo(marketRole.getId(), marketRole.getName());
            roleVos.add(roleVo);
        }
        return roleVos;
    }
}
